﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mirkuz.LocationServices
{
    public delegate void NewLocationAvailableDelegate(LocationProviderBase sender, Location l);
    public delegate void DifficultReceptionDelegate(LocationProviderBase sender);
    public delegate void ErrorDelegate(LocationProviderBase sender,Exception e);

    public class LocationProviderBase : IDisposable
    {
        protected bool _running;
        protected int _pollingtime;

        public event NewLocationAvailableDelegate NewLocationAvailable;
        public event DifficultReceptionDelegate DifficultReception;
        public event ErrorDelegate LocationProviderError;

        public Location CurrentLocation;
        protected void OnNewLocationAvailable(Location l)
        {
            CurrentLocation = l;
            if (NewLocationAvailable != null)
                NewLocationAvailable(this, l);
        }
        protected void OnDifficultReception()
        {
            if (DifficultReception != null)
                DifficultReception(this);
        }
        protected void OnError(Exception e)
        {
            if (LocationProviderError != null)
                LocationProviderError(this, e);
        }
        public int PollingTime
        {
            get { return _pollingtime; }
            set
            {
                if (value >= 10)
                    _pollingtime = value;
                else
                    _pollingtime = 10;
            }
        }

        public virtual void Start()
        {
            if (_running)
                throw new Exception("Already starded");
            _running = true;
        }

        public virtual void Stop()
        {
            if (!_running)
                throw new Exception("Not running");
            _running = false;
        }

        #region IDisposable Members

        public virtual void Dispose()
        {
            
        }

        #endregion
    }

}
